/*--------------登陆------------------*/
	var oTab=document.getElementById('tab');
	var oScan=document.getElementById('scan');
	var oLoginMethod=document.getElementById('login_method')
	oTab.onclick=function(){
		oScan.style.display='none';
		oLoginMethod.style.display='block';
	}

	var oTab2=document.getElementById('tab2');

	oTab2.onclick=function(){
		oScan.style.display='block';
		oLoginMethod.style.display='none';
	}


/*--------------切换普通登陆与手机登陆------------------*/

var aA=document.getElementById('login_wrap').getElementsByTagName('a');
var aSec=document.getElementById('login_method').getElementsByTagName('section');

for(var i=0;i<aA.length;i++){
	aA[i].index=i;
	aA[i].onclick=function(){
		for(var i=0;i<aA.length;i++){
			aSec[i].style.display='none';
			aA[i].className='';
		}
		aSec[this.index].style.display='block';
		aA[this.index].className='active';
		// aA[this.index].style.background='red';
	}
}
/*--------------用户注册------------------*/
var oUser=document.getElementById('username1');
var oPass=document.getElementById('password1');
async function addUser(){
	var data=await Ajax('POST','http://39.105.192.164:9090/apitest/adduser',`username=${oUser.value}&password=${oPass.value}`);
	if(JSON.parse(data).code==1){
		alert(JSON.parse(data).message);
		location.reload();
	}else{
	alert('参数有误');
	}
}
/*--------------用户登陆------------------*/
var oUser2=document.getElementById('username2');
var oPass2=document.getElementById('password2');


async function userLogin(){
	var data=await Ajax('POST','http://39.105.192.164:9090/apitest/login',`username=${oUser2.value}&password=${oPass2.value}`);
	if(JSON.parse(data).code==1){

		setCookie(oUser2.value,oPass2.value,7);
		alert(JSON.parse(data).message);
		location.reload();
	}else{
	alert('参数有误');
	}
}
/*--------------用户cookie登陆------------------*/

oUser2.onblur=function(){
	if(oUser2.value){
		oPass2.value=getCookie(oUser2.value);
	}
}
async function cookieLogin(){
	var data=await Ajax('POST','http://39.105.192.164:9090/apitest/cookielogin',`username=${oUser2.value}&password=${oPass2.value}`);
	if(JSON.parse(data).code==1){
		// alert(JSON.parse(data).message);
		// location.reload();
		console.log('cookie登陆成功');
	}else{
		alert('参数有误');
	}
}

